package com.helloworld.demo.threadbase;

public class ThreadInterrupt {

    static int i = 0;

    public static void main(String[] args) {
        System.out.println("begin");
        Thread thread = new Thread(new Runnable() {
            @Override
            public void run() {
                while (true){
                    i++;
                    System.out.println(i);
                    //Thread.currentThread().isInterrupted() 值判断是否可以中断不清除标志位
                    //Thread.interrupted()//判断并清楚标志位
                    /*if(Thread.interrupted()){
                        System.out.println("Im be interrupt le");
                    }*/
                    System.out.println(Thread.currentThread().isInterrupted());
                    try {
                        Thread.sleep(6000);
                        //wait(6000);
                        System.out.println(Thread.currentThread().isInterrupted());
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }

                    if(Thread.currentThread().isInterrupted()){
                        break;
                    }
                    if(i == 10){
                        break;
                    }
                }
            }
        });
        thread.start();

        try {
            thread.join();
            Thread.sleep(2000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        thread.interrupt();
    }
}
